导航菜单
首页 >  Picture environment  > picture (LaTeX2e unofficial reference manual (May 2024))

picture (LaTeX2e unofficial reference manual (May 2024))

Next: quotation & quote, Previous: minipage, Up: Environments   [Contents][Index]

8.19 picture ¶

Synopses:

\begin{picture}(width,height)picture command\end{picture}

or

\begin{picture}(width,height)(xoffset,yoffset) picture command\end{picture}

Where there may be any number of picture command’s.

An environment to create simple pictures containing lines, arrows,boxes, circles, and text. This environment is not obsolete, but newdocuments typically use much more powerful graphics creation systems,such as TikZ, PSTricks, MetaPost, or Asymptote. None of these arecovered in this document; see CTAN.

To start, here’s an example showing the parallelogram law for adding vectors.

\setlength{\unitlength}{1cm}\begin{picture}(6,6) % picture box will be 6cm wide by 6cm tall \put(0,0){\vector(2,1){4}} % for every 2 over this vector goes 1 up\put(2,1){\makebox(0,0)[l]{\ first leg}} \put(4,2){\vector(1,2){2}}\put(5,4){\makebox(0,0)[l]{\ second leg}}\put(0,0){\vector(1,1){6}}\put(3,3){\makebox(0,0)[r]{sum\ }} \end{picture}

The picture environment has one required argument, a pair ofpositive real numbers (width,height). Multiply these by thevalue \unitlength to get the nominal size of the output, i.e.the space that LaTeX reserves on the output page. This nominal sizeneed not be how large the picture really is; LaTeX will draw thingsfrom the picture outside the picture’s box.

This environment also has an optional argument(xoffset,yoffset). It is used to shift the origin. Unlikemost optional arguments, this one is not contained in square brackets.As with the required argument, it consists of a pair of two realnumbers, but these may also be negative or null. Multiply theseby \unitlength to get the coordinates of the point at thelower-left corner of the picture.

For example, if \unitlength has been set to 1mm, thecommand

\begin{picture}(100,200)(10,20)

produces a box of width 100 millimeters and height 200 millimeters. Thepicture’s origin is the point (10mm,20mm) and so the lower-left corneris there, and the upper-right corner is at (110mm,220mm). When youfirst draw a picture you typically omit the optional argument, leavingthe origin at the lower-left corner. If you then want to modify yourpicture by shifting everything, you can just add the appropriateoptional argument.

Each picture command tells LaTeX where to put something byproviding its position. A position is a pair such as (2.4,-5)giving the x- and y-coordinates. A coordinate is a not a length,it is a real number (it may have a decimal point or a minus sign). Itspecifies a length in multiples of the unit length \unitlength,so if \unitlength has been set to 1cm, then the coordinate2.54 specifies a length of 2.54 centimeters.

LaTeX’s default for \unitlength is 1pt. It is a rigidlength (see Lengths). Change it with the \setlength command(see \setlength). Make this change only outside of a pictureenvironment.

The picture environment supports using standard arithmeticexpressions as well as numbers.

Coordinates are given with respect to an origin, which is by default atthe lower-left corner of the picture. Note that when a position appearsas an argument, as with \put(1,2){...}, it is not enclosed inbraces since the parentheses serve to delimit the argument. Also,unlike in some computer graphics systems, larger y-coordinates arefurther up the page, for example, y = 1 is above y = 0.

There are four ways to put things in a picture: \put,\multiput, \qbezier, and \graphpaper. The mostoften used is \put. This

\put(11.3,-0.3){...}

places the object with its reference point at coordinates(11.3,-0.3). The reference points for various objects will bedescribed below.The \put command creates an LR box (see Modes).Anything that can go in an \mbox (see \mbox & \makebox) cango in the text argument of the \put command. The reference pointwill be the lower left corner of the box. In this picture

\setlength{\unitlength}{1cm}...\begin{picture}(1,1) \put(0,0){\line(1,0){1}} \put(0,0){\line(1,1){1}}\end{picture}

the three dots are just slightly left of the point of the angle formedby the two lines. (Also, \line(1,1){1} does not call for aline of length one; rather the line has a change in the x coordinate of1.)

The \multiput, qbezier, and graphpaper commands aredescribed below.

You can also use this environment to place arbitrary material at anexact location. For example:

\usepackage{color,graphicx} % in preamble ...\begin{center}\setlength{\unitlength}{\textwidth} \begin{picture}(1,1) % leave space, \textwidth wide and tall \put(0,0){\includegraphics[width=\textwidth]{desertedisland.jpg}} \put(0.25,0.35){\textcolor{red}{X Treasure here}}\end{picture}\end{center}

The red X will be precisely a quarter of the \textwidth fromthe left margin, and 0.35\textwidth up from the bottom of thepicture. Another example of this usage is to put similar code in thepage header to get repeat material on each of a document’s pages.

\put\multiput\qbezier\graphpaper\line\linethickness\thinlines\thicklines\circle\oval\shortstack\vector\makebox (picture)\framebox (picture)\frame\dashbox

相关推荐: